package com.fingard.dsp.bank.directbank.cgb02;

import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.directbank.bankInterface.IBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.detail.RetAtsBatPayRecDetail;
import com.fingard.dsp.bank.reqrespobj.single.detail.ReqPayRecDetail;
import com.fingard.net.ConnState;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * @author Cruise
 * @date 2019/4/26
 */
public class CGB02BatPayRec extends CGB02Base implements IBatPayRec {
	@Override
	public RetAtsBatPayRec d_1988_BatPay(ReqBatPayRec p_req1988) throws Exception {
		RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req1988.reqHeader);
		if ("198801".equals(p_req1988.reqHeader.commandCode)) {
			retAts = d_198801_BatPay(p_req1988);
		} else if ("198802".equals(p_req1988.reqHeader.commandCode) || "198805".equals(p_req1988.reqHeader.commandCode)) {
			retAts = d_198802_BatPay(p_req1988);
		}
		return retAts;
	}
	
	public RetAtsBatPayRec d_198801_BatPay(ReqBatPayRec p_req1988) throws Exception {
		RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req1988.reqHeader);
		retAts.reqSeqID = p_req1988.reqBatchNO;

		CGB02Header bankHeader = new CGB02Header();
		bankHeader.reqSeqID = p_req1988.reqBatchNO;
		bankHeader.transCode = "0033";
		
		XmlTextWriter xmlWriter = new XmlTextWriter();
		xmlWriter.autoFormat = false;
		writeCommonHeader(xmlWriter, bankHeader);
		
		XElement tmpXElement = new XElement("Body", "");
		tmpXElement.addChild(new XElement("customerBatchNo", p_req1988.reqBatchNO));
		tmpXElement.addChild(new XElement("accountNo", p_req1988.ownAct));
		tmpXElement.addChild(new XElement("allCount", p_req1988.totalNum));
		tmpXElement.addChild(new XElement("allSalary", p_req1988.totalAmt));
		XElement tmpRecords = new XElement("records", "");
		
		while (p_req1988.readRecord()) {
			XElement tmpRecord = new XElement("record", "");
			ReqPayRecDetail detail = p_req1988.readedDetail;
			// 客户批次子流水号 20
			tmpRecord.addChild(new XElement("customerSalarySeq", detail.askNumber));
			// 交易类型 1 0-行内 1-跨行
			String sameBnk = "1";
			if ("1".equals(detail.sameBnk)) {
				sameBnk = "0";
			}
			tmpRecord.addChild(new XElement("transType", sameBnk));
			// 收方姓名 50
			tmpRecord.addChild(new XElement("inaccname", detail.recName));
			// 收方账号 32
			tmpRecord.addChild(new XElement("inacc", detail.recAct));
			// 收方银行 100
			tmpRecord.addChild(new XElement("inaccbank", detail.recBankName));
			// 收款银行地址 100
			tmpRecord.addChild(new XElement("inaccadd", ""));
			// 联行号 12
			tmpRecord.addChild(new XElement("bankCode", detail.cnapsCode));
			// 金额 16
			tmpRecord.addChild(new XElement("salary", detail.payAmount));
			// 摘要 32
			tmpRecord.addChild(new XElement("remark", detail.useType));
			// 附言 100
            String memo = detail.memo;
            if(StringHelper.isNullOrEmpty(memo)){
                tmpRecord.addChild(new XElement("comment", detail.askNumber));
            }else{
                tmpRecord.addChild(new XElement("comment", memo));
            }
			tmpRecords.addChild(tmpRecord);
		}
		tmpXElement.addChild(tmpRecords);

		// nodeAnalysis(p_req1988.readedDetail.srcXElement, tmpXElement,
		// getCharset());
		xmlWriter.writeXElement(tmpXElement);

		xmlWriter.writeEndDocument();// 写入报文完成

		String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());// 发送银行

		// 测试代码
		if (tmpStrRet[0].length() == 0) {
			StringBuilder tmpSbMsg = new StringBuilder();
			// 解析银行返回
			XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
			if (tmpBkReader != null) {
				String tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/commHead/retCode");
				retAts.respCode = "0";
				retAts.respInfo = "提交成功";
				retAts.reqSeqID = tmpBkReader.getFirstText("/BEDC/Message/commHead/entSeqNo");
				retAts.transState = tmpRetCode;
				retAts.payInfoCode = tmpRetCode;
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = tmpSbMsg.toString();
			}
		} else if (tmpStrRet[0].equals(ConnState.FAIL)) {
			retAts.respCode = "0";
			retAts.respInfo = tmpStrRet[1];
			retAts.reqSeqID = p_req1988.reqBatchNO;
			retAts.transState = PaymentState.FAIL_Payment;
			retAts.payInfoCode = tmpStrRet[0];
		} else {
			retAts.respCode = "-1";
			retAts.respInfo = tmpStrRet[1];
		}
		retAts.writeRetToATS();
		return retAts;
	}
	
	/**
	 * 批量代付提交
	 * 
	 * 参考文档：广发银行银企直联接口说明文档-代收付直通车.doc
	 * 开发接口：3.1.1.1	代付交易（0019）XML格式
	 * 
	 * @param p_req1988
	 * @return
	 * @throws Exception
	 */
	public RetAtsBatPayRec d_198802_BatPay(ReqBatPayRec p_req1988) throws Exception {
		RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req1988.reqHeader);
		retAts.reqSeqID = p_req1988.reqBatchNO;
		
		try {
			CGB02Header bankHeader = new CGB02Header();
			bankHeader.reqSeqID = p_req1988.reqBatchNO;
			bankHeader.transCode = "0019";
			
			XmlTextWriter xmlWriter = new XmlTextWriter();
			xmlWriter.autoFormat = false;
			writeCommonHeader(xmlWriter, bankHeader);
			
			XElement tmpXElement = new XElement("Body", "");
			
			/* 客户批次号 */
			tmpXElement.addChild(new XElement("customerBatchNo", p_req1988.reqBatchNO));
			/* 转出账号 */
			tmpXElement.addChild(new XElement("accountNo", p_req1988.ownAct));
			/* 总笔数 */
			tmpXElement.addChild(new XElement("allCount", p_req1988.totalNum));
			/* 总金额 */
			tmpXElement.addChild(new XElement("allSalary", p_req1988.totalAmt));
			
			XElement tmpRecords = new XElement("records", "");
			while (p_req1988.readRecord()) {
				XElement tmpRecord = new XElement("record", "");
				// 客户批次子流水号
				tmpRecord.addChild(new XElement("customerSalarySeq", p_req1988.readedDetail.askNumber));
				
				// 交易类型
				String transType = "";
				if ("1".equals(p_req1988.readedDetail.sameBnk)) {
					// 同行
					transType = getBankConfig().getMapValueByKey("busiTypeMapping", p_req1988.readedDetail.useType);
					if ("代发工资".equals(transType)) {
						transType = "0";
					} else if ("费用报销".equals(transType)) {
						transType = "2";
					} else if ("其他代付".equals(transType)) {
						transType = "4";
					}
					if (StringHelper.isNullOrEmpty(transType)) {
						transType = "0";
					}
				} else {
					// 跨行
					transType = getBankConfig().getMapValueByKey("busiTypeMapping", p_req1988.readedDetail.useType);
					if ("代发工资".equals(transType)) {
						transType = "1";
					} else if ("费用报销".equals(transType)) {
						transType = "3";
					} else if ("其他代付".equals(transType)) {
						transType = "5";
					}
					if (StringHelper.isNullOrEmpty(transType)) {
						transType = "1";
					}
				}
				if ("198805".equals(p_req1988.reqHeader.commandCode)) {
					transType = "6";
				}
				/* 交易类型 */
				tmpRecord.addChild(new XElement("transType", transType));
				/* 员工编号 */
				tmpRecord.addChild(new XElement("employeeNo", p_req1988.readedDetail.askNumber));
				/* 员工名称 */
				tmpRecord.addChild(new XElement("employeeName", p_req1988.readedDetail.recName));
				/* 员工账号 */
				tmpRecord.addChild(new XElement("employeeAccount", p_req1988.readedDetail.recAct));
				/* 行名 */
				tmpRecord.addChild(new XElement("bankName", p_req1988.readedDetail.cnapsName));
				/* 联行号 */
				tmpRecord.addChild(new XElement("bankCode", p_req1988.readedDetail.cnapsCode));
				/* 金额 */
				tmpRecord.addChild(new XElement("salary", p_req1988.readedDetail.payAmount));
				/* 备注 */
				tmpRecord.addChild(new XElement("remark", p_req1988.readedDetail.useType));
				nodeAnalysis(p_req1988.readedDetail.srcXElement, tmpRecord, getCharset());
				tmpRecords.addChild(tmpRecord);
			}
			tmpXElement.addChild(tmpRecords);
			xmlWriter.writeXElement(tmpXElement);
			xmlWriter.writeEndDocument();
			
			String tmpReqStr = xmlWriter.toXmlString().replace("<retCode />", "<retCode></retCode>");

			String[] tmpStrRet = sendToBank(tmpReqStr);
			if (tmpStrRet[0].length() == 0) {
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if (tmpBkReader != null) {
					String tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/commHead/retCode");
					if(tmpRetCode==null || "".equals(tmpRetCode)){
						tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/Body/retMes");
					}
					retAts.respCode = "0";
					retAts.respInfo = tmpBkReader.getFirstText("/BEDC/Message/Body/retMes");
					retAts.transState = tmpRetCode;
					retAts.payInfoCode = tmpRetCode;
				} else {
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
			} else if (tmpStrRet[0].equals(ConnState.FAIL)) {
				retAts.respCode = "0";
				retAts.respInfo = tmpStrRet[1];
				retAts.reqSeqID = p_req1988.reqBatchNO;
				retAts.transState = PaymentState.FAIL_Payment;
				retAts.payInfoCode = tmpStrRet[0];
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}
		} catch(Exception ex) {
			ex.printStackTrace();
			retAts.respCode = "-1";
			retAts.respInfo = ex.getMessage();
			WriteBankLogLn(ex);
		}
		
		retAts.writeRetToATS();
		return retAts;
	}

	@Override
	public RetAtsQryBatPayRec d_1998_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
		RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req1998.reqHeader);
		if ("198801".equals(p_req1998.reqHeader.commandCode)) {
			retAts = d_1998_198801_QryBatPay(p_req1998);
		}  else if ("198802".equals(p_req1998.reqHeader.commandCode) || "198805".equals(p_req1998.reqHeader.commandCode)) {
			retAts = d_1998_198802_QryBatPay(p_req1998);
		}
		return retAts;
	}
	
	/**
	 * 批量代付查询
	 * 
	 * 参考文档：广发银行银企直联接口说明文档-代收付直通车.doc
	 * 开发接口：3.1.1.2	代付交易明细查询（1030）XML格式
	 * 
	 * @param p_req1998
	 * @return
	 * @throws Exception
	 */
	public RetAtsQryBatPayRec d_1998_198801_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
		RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req1998.reqHeader);
		retAts.reqSeqID = p_req1998.reqBatchNO;
		
		try {
			CGB02Header bankHeader = new CGB02Header();
			bankHeader.reqSeqID = p_req1998.reqHeader.transSeqID;
			bankHeader.transCode = "0034";
			XmlTextWriter xmlWriter = new XmlTextWriter();// 发银行报文的XML对象
			xmlWriter.autoFormat = false;
			writeCommonHeader(xmlWriter, bankHeader);// 写入通用的头部节点
			xmlWriter.writeStartElement("Body");
			xmlWriter.writeElementString("customerBatchNo", p_req1998.reqBatchNO);
			xmlWriter.writeElementString("customerSalarySeq", " ");
			xmlWriter.writeEndDocument();
		
			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
			if (tmpStrRet[0].length() == 0) {
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if (tmpBkReader != null) {

					String tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/commHead/retCode");
					retAts.respCode = "0";
					// String tmpHostStatus =
					// tmpBkReader.getFirstText("/BEDC/Message/Body/hostStatus");
					if ("000".equals(tmpRetCode)) {

						while (tmpBkReader.read("/BEDC/Message/Body/records/record")) {
							RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
							tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("customerSalarySeq");
							// 行内汇款：
							// 6：主机交易成功
							// 7：主机交易失败
							// 8：状态未知，没有收到后台系统返回的应答
							// 跨行汇款：
							// A：支付系统正在处理
							// B：处理成功
							// C：处理失败
							// D：状态未知
							// E：大额查证
							// 9：查证取消交易
							// b:汇款失败已冲账
							tmpRetDetail.result = tmpRetCode + "+" + tmpBkReader.readedXElement.getSingleText("bankstatus");
							String errorreason = tmpBkReader.readedXElement.getSingleText("errorreason");
							if (errorreason != null && !"".equals(errorreason)) {
								tmpRetDetail.payInfoCode = tmpRetCode + "+" + errorreason;
								tmpRetDetail.memo = errorreason;
							} else {
								tmpRetDetail.payInfoCode = tmpRetDetail.result;
								tmpRetDetail.memo = tmpRetDetail.result;
							}
							retAts.writeRetDetail(tmpRetDetail);
						}
					} else if ("888".equals(tmpRetCode)) {
						retAts.respCode = "0";
						retAts.transState = tmpRetCode;
						retAts.payInfoCode = tmpRetCode;
						retAts.respInfo = "接收处理中,请稍后查询";

					} else {
						if ("242".equals(tmpRetCode) && !canBeNotExist(p_req1998, retAts, 30)) {
							retAts.writeAfterDetail();
							return retAts;
						}
						retAts.respCode = "0";
						retAts.transState = tmpRetCode;
						retAts.payInfoCode = tmpRetCode;
						retAts.respInfo = "请求失败";
					}
				} else {
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
				if (StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
					retAts.reqSeqID = p_req1998.reqBatchNO;
				}
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}

		} catch (Exception e) {
			retAts.respCode = "-1";
			retAts.respInfo = e.getMessage();
			e.printStackTrace();
		}
		retAts.writeAfterDetail();
		return retAts;
	}
	
	public RetAtsQryBatPayRec d_1998_198802_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
		RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req1998.reqHeader);
		retAts.reqSeqID = p_req1998.reqBatchNO;
		
		try {
			CGB02Header bankHeader = new CGB02Header();
			bankHeader.reqSeqID = p_req1998.reqHeader.transSeqID;
			bankHeader.transCode = "1030";
			
			XmlTextWriter xmlWriter = new XmlTextWriter();
			xmlWriter.autoFormat = false;
			writeCommonHeader(xmlWriter, bankHeader);
			
			xmlWriter.writeStartElement("Body");
			
			String transType = getBankConfig().getMapValueByKey("busiTypeMapping", p_req1998.useType);
			if ("代发工资".equals(transType)) {
				transType = "3";
			} else if ("费用报销".equals(transType)) {
				transType = "1";
			} else if ("其他代付".equals(transType)) {
				transType = "2";
			}
			if ("198805".equals(p_req1998.reqHeader.commandCode)) {
				transType = "4";
			}
			if (StringHelper.isNullOrEmpty(transType)) {
				transType = "3";
			}
			/* 业务类型 */
			xmlWriter.writeElementString("businessType", transType);
			/* 客户批次号 */
			xmlWriter.writeElementString("customerBatchNo", p_req1998.reqBatchNO);
			/* 客户批次子流水 */
			xmlWriter.writeElementString("customerSalarySeq", " ");
			xmlWriter.writeEndDocument();
		
			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
			if (tmpStrRet[0].length() == 0) {
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if (tmpBkReader != null) {
					String tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/commHead/retCode");
					if ("000".equals(tmpRetCode)) {
						retAts.respCode = "0";
						while (tmpBkReader.read("/BEDC/Message/Body/records/record")) {
							RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
							tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("customerSalarySeq");
							tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("inacc");
							tmpRetDetail.recName = tmpBkReader.readedXElement.getSingleText("inname");
							tmpRetDetail.payAmount = tmpBkReader.readedXElement.getSingleText("salary");
							tmpRetDetail.result = tmpRetCode + "+" + tmpBkReader.readedXElement.getSingleText("flag");
							String payInfoCode = tmpBkReader.readedXElement.getSingleText("errCode");
							if(payInfoCode ==null || "".equals(payInfoCode)){
								payInfoCode = tmpBkReader.readedXElement.getSingleText("errorMsg");
							}
							tmpRetDetail.payInfoCode = payInfoCode;
							tmpRetDetail.memo = tmpBkReader.readedXElement.getSingleText("errorMsg");
							retAts.writeRetDetail(tmpRetDetail);
						}
					} else {
						retAts.respCode = "-1";
						retAts.respInfo = tmpRetCode;
					} 
				} else {
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			retAts.respCode = "-1";
			retAts.respInfo = ex.getMessage();
			WriteBankLogLn(ex);
		}
		
		retAts.writeAfterDetail();
		return retAts;
	}

	/**
	 * 批量代扣提交
	 * 
	 * 参考文档：广发银行银企直联接口说明文档-易收款1.5.doc
	 * 开发接口：3.1.1.8	批量代扣（2042）XML格式
	 */
	@Override
	public RetAtsBatPayRec d_9188_BatPay(ReqBatPayRec p_req9188) throws Exception {
		RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req9188.reqHeader);
		retAts.reqSeqID = p_req9188.reqBatchNO;
		
		try {
			CGB02Header bankHeader = new CGB02Header();
			bankHeader.reqSeqID = p_req9188.reqBatchNO;
			bankHeader.transCode = "2042";
			
			XmlTextWriter xmlWriter = new XmlTextWriter();
			xmlWriter.autoFormat = false;
			writeCommonHeader(xmlWriter, bankHeader);
			
			XElement tmpXElement = new XElement("Body", "");
			/* 客户批次号 */
			tmpXElement.addChild(new XElement("customerBatchNo", p_req9188.reqBatchNO));
			/* 批次总笔数 */
			tmpXElement.addChild(new XElement("allCount", p_req9188.totalNum));
			/* 批次总金额 */
			tmpXElement.addChild(new XElement("allAmount", p_req9188.totalAmt));
			/* 入账账号 */
			tmpXElement.addChild(new XElement("inAcc", p_req9188.ownAct));
			/* 托收类型 */
			tmpXElement.addChild(new XElement("bussType", "006"));
			
			XElement tmpRecords = new XElement("records", "");
			while (p_req9188.readRecord()) {
				XElement tmpRecord = new XElement("record", "");
				ReqPayRecDetail detail = p_req9188.readedDetail;
				// 批次子交易编号
				tmpRecord.addChild(new XElement("subNo", detail.askNumber));
				// 银行协议号 
				tmpRecord.addChild(new XElement("signBankNo", p_req9188.readedDetail.authCode));
				// 付方账号
				tmpRecord.addChild(new XElement("outAcc", detail.payAct));
				// 付方姓名 
				tmpRecord.addChild(new XElement("outAccName", detail.payName));
				// 金额
				tmpRecord.addChild(new XElement("amount", detail.payAmount));
				// 附言
				tmpRecord.addChild(new XElement("reason", detail.useType));
				// 备注
				tmpRecord.addChild(new XElement("remark", detail.memo));
				// 预留字段1
				tmpRecord.addChild(new XElement("reserve1", ""));
				// 预留字段2
				tmpRecord.addChild(new XElement("reserve2", ""));
				nodeAnalysis(p_req9188.readedDetail.srcXElement, tmpRecord, getCharset());
				tmpRecords.addChild(tmpRecord);
			}
			tmpXElement.addChild(tmpRecords);
			xmlWriter.writeXElement(tmpXElement);
			xmlWriter.writeEndDocument();

			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
			if (tmpStrRet[0].length() == 0) {
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if (tmpBkReader != null) {
					String tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/commHead/retCode");
					retAts.respCode = "0";
					String batchStatus = tmpBkReader.getFirstText("/BEDC/Message/Body/batchStatus");
					retAts.transState = tmpRetCode + "+" + batchStatus;
					retAts.payInfoCode = tmpRetCode + "+" + batchStatus;
				} else {
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
			} else if (tmpStrRet[0].equals(ConnState.FAIL)) {
				retAts.respCode = "0";
				retAts.respInfo = tmpStrRet[1];
				retAts.reqSeqID = p_req9188.reqBatchNO;
				retAts.transState = PaymentState.FAIL_Payment;
				retAts.payInfoCode = tmpStrRet[0];
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			retAts.respCode = "-1";
			retAts.respInfo = ex.getMessage();
			WriteBankLogLn(ex);
		}
		
		retAts.writeRetToATS();
		return retAts;
	}
	
	/**
	 * 批量代扣状态查询
	 * 
	 * 参考文档：广发银行银企直联接口说明文档-易收款1.5.doc
	 * 开发接口：3.1.1.9	批量代扣查询（2043）XML格式
	 */
	@Override
	public RetAtsQryBatPayRec d_9198_QryBatPay(ReqQryBatPayRec p_req9198) throws Exception {
		RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req9198.reqHeader);
		retAts.reqSeqID = p_req9198.reqBatchNO;
		
		try {
			CGB02Header bankHeader = new CGB02Header();
			bankHeader.reqSeqID = p_req9198.reqHeader.transSeqID;
			bankHeader.transCode = "2043";
			
			XmlTextWriter xmlWriter = new XmlTextWriter();
			xmlWriter.autoFormat = false;
			writeCommonHeader(xmlWriter, bankHeader);
			
			xmlWriter.writeStartElement("Body");
			/* 客户批次号 */
			xmlWriter.writeElementString("customerBatchNo", p_req9198.reqBatchNO);
			xmlWriter.writeStartElement("records");
			xmlWriter.writeStartElement("record");
			/* 子交易编号 */
			xmlWriter.writeElementString("subNo", "");
			xmlWriter.writeEndDocument();
		
			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
			if (tmpStrRet[0].length() == 0) {
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if (tmpBkReader != null) {
					String tmpRetCode = tmpBkReader.getFirstText("/BEDC/Message/commHead/retCode");
					if ("000".equals(tmpRetCode)) {
						retAts.respCode = "0";
						retAts.respInfo = tmpBkReader.getFirstText("/BEDC/Message/Body/batchErrMsg");
						
						String status = tmpBkReader.getFirstText("/BEDC/Message/Body/batchStatus");
						if ("1".equals(status) || "2".equals(status)) {
							while (tmpBkReader.read("/BEDC/Message/Body/records/record")) {
								RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
								tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("subNo");
								tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("outAcc");
								tmpRetDetail.payAmount = tmpBkReader.readedXElement.getSingleText("outAccName");
								tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("amount");
								String tranStatus = tmpBkReader.readedXElement.getSingleText("tranStatus1");
								tmpRetDetail.result = status + "+" + tranStatus;
								tmpRetDetail.memo = tmpBkReader.readedXElement.getSingleText("errMsg");
								tmpRetDetail.payInfoCode = tmpBkReader.readedXElement.getSingleText("errMsg");
								retAts.writeRetDetail(tmpRetDetail);
							}
						} else {
							retAts.transState = status;
							retAts.payInfoCode = tmpBkReader.getFirstText("/BEDC/Message/Body/batchErrMsg");
						}
					} else {
						retAts.respCode = "-1";
						retAts.respInfo = tmpRetCode;
					}
				} else {
					retAts.respCode = "-1";
					retAts.respInfo = tmpSbMsg.toString();
				}
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = tmpStrRet[1];
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			retAts.respCode = "-1";
			retAts.respInfo = ex.getMessage();
			WriteBankLogLn(ex);
		}
		
		retAts.writeAfterDetail();
		return retAts;
	}
}
